# config.py
import logging
import sys
import re

class Config:
    # 数据库配置
    DB_CONFIG = {
        "driver": "ODBC Driver 18 for SQL Server",
        "server": "localhost",
        "database": "WarehouseMonitor",
        "user": "sa",
        "password": "star2025god",
        "trust_cert": "yes"
    }

    # 数据解析配置
    DATA_PATTERN = re.compile(
        r'FT(\d+\.\d{1,2})H(\d+\.\d{1,2})'  # 匹配FT后的温度值和H后的湿度值
    )
    SERIAL_TERMINATOR = b'\n'  # 修改终止符为换行符

    # 硬件配置
    SERIAL_PORT = 'COM7'
    SERIAL_BAUD = 9600

    # 传感器阈值
    VALID_RANGES = {
        "temperature": (0, 50),
        "humidity": (20, 95)
    }

    # 日志配置
    LOGGING_CONFIG = {
        "level": logging.INFO,
        "format": "%(asctime)s - %(levelname)s - %(message)s",
        "stream": sys.stdout
    }

    # Web服务配置
    WEB_HOST = '0.0.0.0'
    WEB_PORT = 5000

    # 模板配置
    TEMPLATE_FOLDER = "templates"